package com.sfdk.pools
{
    import flash.display.Bitmap;
    import flash.display.BitmapData;
import flash.utils.Dictionary;

    public class BitmapDataPool
	{
		private static var instance_ : BitmapDataPool;
		
		private var _pool : Dictionary;
		private var totalSize_ : int;
		
		public function BitmapDataPool()
		{
			_pool = new Dictionary();
			totalSize_ = 0;
			instance_ = this;	
		}
		
		public static function get instance() : BitmapDataPool
		{
			return instance_;
		}
		
		/**
		 * Ajoute les spritesheet à la map
		 * Renvoi :
		 * 			-1 si la spritesheet existe deja
		 * 			1 si tout est ok
		 **/
		public function addToPool(tilesetImage : BitmapData, name : String) : int
		{
			if(_pool[name] != null)
				return -1;
				
			_pool[name] = tilesetImage;
			return 1;				
		}
			
		public function removeFromPool(name : String) : void
		{
			_pool[name] = null;
		}
		
		public function getFromPool(name : String) : BitmapData
		{
            return _pool[name] as BitmapData;
		}

        public function getAsBitmap(name : String) : Bitmap
		{
            return new Bitmap(_pool[name] as BitmapData);
		}

		
		public function isInPool(name : String) : Boolean
		{
			return (_pool[name] != null);
		}
	}
}